<template>
	<view class="sign">
		<view class="sign_header">
			<view class="picture">
				<image src="../../static/workOrder/Group1035.png" mode="" style="width: 120rpx; height: 110rpx;">
				</image>
			</view>
			<view class="smart">
				智慧小区
			</view>
		</view>
		<view class="sign_center">
			<u-form :model="form" ref="uForm">
				<u-input v-model="form.mobile" :type="type" :border="border" placeholder="手机号/邮箱登录" />
				<u-input v-model="form.code" :type="type2" :border="border" placeholder="密码"
					:password-icon="passwordIcon" />
			</u-form>
			<view class="other">
				<text class="password">忘记密码</text>
				<text class="user">注册新用户</text>
			</view>
			<!-- <u-button size="medium" shape="circle" @click="submit">登录</u-button> -->
			<button type="default" class="btn" @click="login">登录</button>
		</view>
		<view class="sign_footer">
			<u-checkbox-group width="545rpx" size="30rpx" :label-disabled="true">
				<u-checkbox @change="checkboxChange" v-model="item.checked" v-for="(item, index) in list" :key="index"
					:name="item.name">已阅读并同意<text style="margin: 0 10rpx;color: #296d93;"
						@click="userAgreement">用户协议</text>和<text style="margin-left: 10rpx;color: #296d93;"
						@click="privacyPolicy">隐私政策</text></u-checkbox>
			</u-checkbox-group>
		</view>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import tabBar from '../../store/modules/tabBar.js';
	export default {
		data() {
			return {
				form: {
					// 外网
					// mobile: 'cjznAdmin',
					// code: '123456',
					// 本地
					// 管理员
					mobile: 'kjadmin',
					code: '123456',
					// mobile: 'hsAdmin',
					// code: '123456',
					// mobile: 'cs',
					// code: '123456',
					// 维修人员
					// mobile: 'qwer123',
					// code: '123456',
				},
				type: 'text',
				type2: 'password',
				border: false,
				passwordIcon: false,
				list: [{
					name: 'apple',
					checked: false,
					disabled: false
				}],
				value:''
			}
		},
		onLoad() {
			// wx.login({
			// 	success: (res) => {
			// 		if (res.code) {
			// 			//微信登录成功 已拿到code  
			// 			console.log(res)
			// 			this.$http.get('loginUser', {
			// 				code: res.code,
			// 			}).then(res => {
			// 				// console.log(11111)
			// 				console.log(res)
			// 			})
			// 		} else {
			// 			console.log('登录失败！' + res.errMsg)
			// 		}
			// 	} 
			// 	  success: (res) => {
			// 	    if (res.code) {
			// 			let code =res.code
			// 			let appid="wxcee3a8e84e407412"
			// 			let secret="afbe2888fb6fc73d10f8693f7467146f"
			// 	      //发起网络请求
			// 	      wx.request({
			// 	        url: 'https://api.weixin.qq.com/sns/jscode2session?appid='+appid+'&secret='+secret+'&js_code='+code+'&grant_type=authorization_code',
			// 			method: 'GET',
			// 			success: (res2)=>{
			// 				console.log(res2.data)
			// 			}
			// 	      })
			// 	    } else {
			// 	      console.log('登录失败！' + res.errMsg)
			// 	    }
			// 	  }
			// });
		},
		methods: {
			// 用户协议
			userAgreement() {
				// console.log()
				this.openUrl('/pagesB/sign/userAgreement/userAgreement')
			},
			// 隐私政策
			privacyPolicy() {
				this.openUrl('/pagesB/sign/privacyPolicy/privacyPolicy')
			},
			login() {
				if(this.value==false) {
					this.$refs.uToast.show({
						title: '请勾选用户协议和隐私政策',
					})
				} else {
					this.$http.get('loginUser', {
						userName: this.form.mobile,
						password: this.form.code,
					}).then(res => {
						if (res.code == '200') {
							uni.setStorageSync('token', res.data.token)
							uni.setStorageSync('setModel', res.data.loginUser)
							uni.setStorageSync('plantNo', res.data.loginUser.plantNo)
							uni.setStorageSync('userType', res.data.loginUser.staffType)
							// debugger
							// tabBar.base()
							// this.openUrl('/pages/application/application')
							uni.switchTab({
								url: '/pages/my/my'
							})
						} else {
							this.$refs.uToast.show({
								title: res.msg,
							})
						}

						console.log(res, '课程分类')
						// this.msg = res.code
						// uni.setStorageSync('userType', res.code);
					})
				}
				// uni.request({
				//     url: 'http://112.123.228.65:9100/?userName=hsAdmin&password=123456', //仅为示例，并非真实接口地址。
				// 	method:'get',
				//   //   data: {
				//   //       userName: 'hsAdmin',
				// 		// password: '123456',
				//   //   },
				//     success: (res) => {
				//         console.log(res);
				// 				uni.switchTab({
				// 					url: '/pages/my/my'
				// 				})
				//     }
				// });
			},
			// 选中任一checkbox时，由checkbox-group触发
			checkboxChange(e) {
				console.log(e);
				this.value=e.value
			},
		}
	}
</script>

<style lang="scss" scoped>
	.sign {
		.sign_header {
			width: 168rpx;
			height: 190rpx;
			margin: 221rpx auto 0;

			.picture {
				width: 120rpx;
				height: 110rpx;
				margin: 0 auto;
			}

			.smart {
				margin-top: 11rpx;
				font-size: 42rpx;
				font-weight: medium;
			}
		}

		/deep/.sign_center {
			margin: 190rpx auto 0;
			width: 416rpx;

			.u-input {
				border-bottom: 1px solid #999999;
			}

			.other {
				display: flex;
				justify-content: space-between;
				margin-top: 18rpx;
			}

			.btn {
				width: 269rpx;
				height: 70rpx;
				margin-top: 116rpx;
				font-size: 24rpx;
				line-height: 70rpx;
				color: #fff;
				border-radius: 54rpx;
				background-color: #333333;
			}
		}

		.sign_footer {
			margin: 100rpx auto 0;
			width: 528rpx;
		}
	}
</style>
